package base.utils.date;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class TimeChangeDateFormatUtils {



    public static String changeDateStringFormat(String oldDateString, DateTypeEnum oldDateFormat, DateTypeEnum newDateFormat){

        Date date1 = null;
        DateFormat df2 = null;
        try {
            DateFormat df = new SimpleDateFormat(oldDateFormat.getFormat());
            Date date = df.parse(oldDateString);

            SimpleDateFormat df1 = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
            date1 = df1.parse(date.toString());
            df2 = new SimpleDateFormat(newDateFormat.getFormat());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date1 == null ? null : df2.format(date1);
    }


     public static String changeDateStringFormat(Date oldDate, DateTypeEnum newDateFormat){

        Date date1 = null;
        DateFormat df2 = null;
        try {

            SimpleDateFormat df1 = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", Locale.UK);
            date1 = df1.parse(oldDate.toString());
            df2 = new SimpleDateFormat(newDateFormat.getFormat());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date1 == null ? null : df2.format(date1);
    }





}
